package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.query.TravelQueryObject;
import cn.wolfcode.trip.base.service.ITravelCommendService;
import cn.wolfcode.trip.base.service.ITravelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

/**
 * @author by mycp
 * @Classname TravelReleaseController
 * @Description TODO 已发布游记处理器
 * @Date 2018/11/5 18:55
 */
@Controller
@RequestMapping("/travelRelease")
public class TravelReleaseController {
    @Autowired
    private ITravelService travelService;
    @Autowired
    private ITravelCommendService travelCommendService;

    /**
     * 处理获取所有已发布游记
     * @return
     */
    @RequestMapping("/list")
    public String list(@ModelAttribute("qo")TravelQueryObject qo, Model model){
        // 已发布游记的状态为2
        qo.setState(2);
        // 按照最近更新发布时间进行排序
        qo.setOrderBy("t.releaseTime desc");
        // 已发布游记为公开
        qo.setIsPublic(true);
        model.addAttribute("pageInfo", travelService.queryTravel(qo));

        // 查询本周推荐游记数 本月推荐游记数集合
        int[] counts =  travelCommendService.selectForCount();

        model.addAttribute("counts", counts);

        return "travelRelease/list";
    }
}
